package common;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.FrameLayout;


/**
 * Depiction: 视图抽象类
 * <p>
 * Modify:
 * <p>
 * Author: Kevin Lynn
 * <p>
 * Create Date：2016年1月21日 下午7:06:01
 * <p>
 * 
 * @version 1.0
 * @since 1.0
 */
public abstract class AbsBaseView extends FrameLayout {
	protected ViewHandler	   mHandler;
	private AbsActivity		   activity;
	
	public AbsBaseView(Context context) {
		this(context, null);
	}
	
	/**
	 * @param context
	 * @param attrs
	 */
	public AbsBaseView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}
	
	/**
	 * @param context
	 * @param attrs
	 * @param defStyleAttr
	 */
	public AbsBaseView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		setBackgroundColor(Color.WHITE);
		inflate(context, layoutResId(), this);
		mHandler = new ViewHandler(this);
	}
	
	public AbsActivity getActivity() {
		if (getContext() instanceof AbsActivity) {
			return (AbsActivity) getContext();
		}
		return activity;
	}
	
	public void setAbsActivity(AbsActivity activity) {
		this.activity = activity;
	}
	@SuppressWarnings ("unchecked")
	public <T> T $(int viewID) {
		return (T) mHandler.get(viewID);
	}
	
	public String getTag() {
		return getClass().getSimpleName();
	}
	
	public abstract int layoutResId();

	public abstract void loadData(Object data);


	public abstract boolean isEmpty();
	
}
